{% extends "base.html" %}

{% block css %}
{% if current == 'blob' %}
<link href='/static/less/min/syntaxhighlighter.min.css?timestamp={{gitshell.timestamp}}' rel='stylesheet'>
<link href='/static/less/app/highlight/default.css?timestamp={{gitshell.timestamp}}' rel='stylesheet'>
{% endif %}
{% block subcss %}{% endblock %}
{% endblock %}

{% block container_class_name %}repo{% endblock %}

{% block container %}
<div class="subhead repo-global-bar">
  <div class="container">
    <ul class="breadcrumb">
      <li class="user">{%if repo.is_public%}<i class="icon-unlock"></i>{%else%}<i class="icon-lock"></i>{%endif%}<a href="/{{user_name}}/">{{user_name}}</a><span class="divider">/</span></li>
      <li><a href="/{{user_name}}/{{repo_name}}">{{repo_name}}</a></li>
      <li class="repo-nav dropdown">
        <a href="/{{user_name}}/{{repo_name}}/" class="dropdown-toggle" data-toggle="dropdown">
          <span class="btn btn-mini btn-success"><i class="icon-caret-down"></i></span>
        </a>
        <ul class="dropdown-menu nav nav-list">
          <li{% if current == 'index' or current == 'tree' or current == 'blob' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/" data-original-title="Code" rel="tooltip"><span><i class="icon-code"></i>代码</span></a></li>
          <li{% if current == 'issues' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/issues/" data-original-title="Issues" rel="tooltip"><span><i class="icon-bug"></i>问题</span></a></li>
          <li{% if current == 'compare' or current == 'pull' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/pulls/" data-original-title="Pull Request" rel="tooltip"><span><i class="icon-code-fork"></i>合并请求</span></a></li>
          <li{% if current == 'pulse' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/pulse/" data-original-title="Overview" rel="tooltip"><span><i class="icon-desktop"></i>总览</span></a></li>
          {#<li{% if current == 'stats' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/stats/" data-original-title="Graph" rel="tooltip"><span><i class="icon-th"></i>统计</span></a></li>#}
          {% if is_owner %}
          <li{% if current == 'settings' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/settings/" data-original-title="Setting" rel="tooltip"><span><i class="icon-wrench"></i>设置</span></a></li>
          {% endif %}
        </ul>
      </li>
      {% if parent_repo %}
        <li class="forked">
          <p><span>forked from</span><a href="/{{parent_repo.username}}/">{{parent_repo.username}}</a>/<a href="/{{parent_repo.username}}/{{parent_repo.name}}/">{{parent_repo.name}}</a></p>
        </li>
      {% endif %}
    </ul>

    <ul class="repo-actions">
      <li class="clone-url">
        <a href="#" class="btn btn-mini btn-primary menu-toggle" id="cloneUrlToggle"><i class="icon-terminal"></i>克隆</a>
        <div class="clone-menu" id="cloneMenu">
          {% if repo.status != 0 %}
          <p class="alert alert-info">正在初始化...</p>
          {% endif %}

          {% if has_fork_right %}
          <dl class="url colspan">

            <dt class="span">
            {% if is_repo_member or is_teamMember %}
              <a href="#" class="btn" id="urlType"><span>HTTP</span><i class="icon-caret-down"></i></a>
              <ul class="nav nav-list" id="urlTypeMenu">
                <li><a href="#" id="httpFork">HTTP</a></li>
                <li><a href="#" id="sshFork">SSH</a></li>
                {% if repo.auth_type == 0 %}
                  <li><a href="#" id="gitFork">GIT</a></li>
                {% endif %}
              </ul>
            {% else %}
              <a href="#" class="btn dropdown-toggle" id="urlType"><span>HTTP</span>{% if repo.auth_type == 0 %}<i class="icon-caret-down"></i>{% endif %}</a>
              <ul class="nav nav-list" id="urlTypeMenu">
                <li><a href="#" id="httpFork">HTTP</a></li>
                {% if repo.auth_type == 0 %}
                  <li><a href="#" id="gitFork">GIT</a></li>
                {% endif %}
              </ul>
            {% endif %}
            </dt>

            <dd class="url-holder">
              <input class="middle" id="urlData" type="text" value="https://gitshell.com/{{user_name}}/{{repo_name}}.git" readonly="readonly">
            </dd>
          </dl>
          {% endif %}

        </div>
      </li>
      <li class="btn-group">
        <a href="/{{user_name}}/{{repo_name}}/compare/" class="btn btn-mini first"><i class="icon-random"></i>比较</a>
        <a href="/{{user_name}}/{{repo_name}}/pull/new/" class="btn btn-mini last"><i class="icon-code-fork"></i>合并请求</a>
      </li>
      <li class="btn-group">
        {% if is_watched_repo %}
        <a class="btn btn-mini unwatch first" data-original-title="Unwatch" rel="tooltip" href="javascript: void(0)">取消关注</a>
        {% else %}
        <a class="btn btn-mini watch first" data-original-title="Watch" rel="tooltip" href="javascript: void(0)">关注</a>
        {% endif %}
        {% if is_stared_repo %}
        <a class="btn btn-mini unstar last" data-original-title="Unstar" rel="tooltip" href="javascript: void(0)">取消收藏</a>
        {% else %}
        <a class="btn btn-mini star last" data-original-title="Star" rel="tooltip" href="javascript: void(0)">收藏</a>
        {% endif %}
      </li>
      {% if has_fork_right %}
      <li class="btn-group">
        <a class="btn btn-mini fork first" data-original-title="Fork" rel="tooltip" href="javascript: void(0)">派生</a>
        <span class="btn btn-mini count last" title="衍生次数" href="/{{user_name}}/{{repo_name}}/clone_watch_star/">{{repo.fork}}</span>
      </li>
      {% endif %}
    </ul>
  </div>
</div>

<div class="content">
  <div class="container{% block repo_container_class_name %}{% endblock %}">

    {% block repo_description %}{% endblock %}

    {% if current == 'index' or current == 'tree' or current == 'blob' or current == 'commits' or current == 'branches' or current == 'tags' or current == 'refs_graph' %}
    <ul class="nav nav-tabs">
      <li{% if current == 'index' or current == 'tree' or current == 'blob' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/tree/{{refs}}/">代码</a></li>
      <li{% if current == 'commits' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/commits/{{refs}}/">提交{%if repo.commit%}<span class="label label-mini{% if current == 'commits' %} label-success{% endif %}">{{repo.commit}}</span>{%endif%}</a></li>
      <li{% if current == 'branches' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/branches/{{refs}}/">分支{%if refs_meta.branch_count%}<span class="label label-mini{% if current == 'branches' %} label-success{% endif %}">{{refs_meta.branch_count}}</span>{%endif%}</a></li>
      <li{% if current == 'tags' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/tags/{{refs}}/">标签{%if refs_meta.tag_count%}<span class="label label-mini{% if current == 'tags' %} label-success{% endif %}">{{refs_meta.tag_count}}</span>{%endif%}</a></li>
      <li{% if current == 'refs_graph' %} class="active"{% endif %}><a href="/{{user_name}}/{{repo_name}}/refs/graph/{{refs}}/">分支图</a></li>
    </ul>
    {% endif %}

    {% block bubbleheader %}{% endblock %}
    {% block subcontainer %}{% endblock %}

  </div>
</div>

{% endblock %}

{% block js %}
<script>
  $(function(){

    $('.repocrumb span[data-toggle]').hover(
      function(){
        $(this).find('.icon-caret-down').show();
      },function(){
        $(this).find('.icon-caret-down').hide();
      }
    );

    $('#cloneUrlToggle').click(function(e){
      e.stopPropagation();
      $('#cloneMenu').toggle();
      $('#urlData').select();
    });

    $('#cloneMenu').children().click(function(e){
      e.stopPropagation();
    });

    $('html').click(function(e) {
      var target = $(e.target);
      if(!target.is('#cloneMenu')) {
        return true;
        $('#cloneMenu').hide();
      }
    });

    $('#urlType').click(function(e){
      e.stopPropagation();
      $('#urlTypeMenu').toggle();
    });

    $('#urlTypeMenu a').click(function(e) {
      e.preventDefault();
      var txt = $(this).text();
      $('#urlType').find('span').text(txt);
      $('#urlTypeMenu').hide();
      switch(this.id) {
        case 'sshFork':
          $('#urlData').val('git@gitshell.com:{{user_name}}/{{repo_name}}.git').select();
          break;
        case 'httpFork':
          $('#urlData').val('https://gitshell.com/{{user_name}}/{{repo_name}}.git').select();
          break;
        case 'gitFork':
          $('#urlData').val('git://gitshell.com/{{user_name}}/{{repo_name}}.git').select();
          break;
      };
    });

    $('#urlData').mouseover(function() {
      $(this).addClass('selected').select();
    });

    $('.repo-actions .watch').click(function() {
      $.post('/{{user_name}}/{{repo_name}}/watch/', {csrfmiddlewaretoken: '{{ csrf_token }}'}, function(json){
        window.location = window.location;
      });
    });

    $('.repo-actions .unwatch').click(function() {
      $.post('/{{user_name}}/{{repo_name}}/unwatch/', {csrfmiddlewaretoken: '{{ csrf_token }}'}, function(json){
        window.location = window.location;
      });
    });

    $('.repo-actions .star').click(function() {
      $.post('/{{user_name}}/{{repo_name}}/star/', {csrfmiddlewaretoken: '{{ csrf_token }}'}, function(json){
        window.location = window.location;
      });
    });

    $('.repo-actions .unstar').click(function() {
      $.post('/{{user_name}}/{{repo_name}}/unstar/', {csrfmiddlewaretoken: '{{ csrf_token }}'}, function(json){
        window.location = window.location;
      });
    });

    $('.repo-actions .fork').click(function() {
      $.post('/{{user_name}}/{{repo_name}}/fork/', {csrfmiddlewaretoken: '{{ csrf_token }}'}, function(json){
        window.location = '/{{user.username}}/{{repo_name}}/';
      });
    });
    $('.branches .dropdown-toggle').click(function(event) {
      $('#i_git_url').select();
    });

    $('.c_repo_action').tooltip({
      selector: "a[rel=tooltip]"
    });

    $('.repo-admin-edit').hide();
    $('.repo-summary > .description').hover(
      function(){
        $('.repo-admin-edit').show();
      },function(){
        $('.repo-admin-edit').hide();
      }
    );

    $('.sidenav a.btn').tooltip();

  });
</script>
{% block subjs %}{% endblock %}
{% endblock %}
